'use strict';

var Model = require('../../model/mysql/book.js');
var debug = require('debug')('book');
var sequelize = require('../../model/mysql.js');

function MysqlDao() {
    let self = this instanceof MysqlDao ? this : new MysqlDao();
    return self;
}
module.exports = MysqlDao;
let theProto = MysqlDao.prototype;

MysqlDao.prototype.save = function*(json) {
    yield Model.sync();// create table success

    let instance = Model.build(json);
    let result = yield instance.save();

    return result;
};

MysqlDao.prototype.findById = function*(id) {
    return yield Model.findById(id);
};

MysqlDao.prototype.rawQuery = function*(sql) {
    let result = yield sequelize.query(sql);
    return result[0];
};